package com.github.willisaway.core.base;

import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;

import lombok.Data;

@Data
public class ModuleReturn implements Serializable {
    private static final long serialVersionUID = 1L;

    private int status = 200;//请求状态码
    private String error = "";//错误详细信息
    private String message = "";// 提示信息
    private long timestamp = 0L;
    private Map<String, Object> data = new HashMap<String, Object>();// 返回信息map

    public ModuleReturn() {
    }

    public ModuleReturn(int status) {
        this.status = status;
    }
    
    public ModuleReturn(String message) {
        this.message = message;
    }

    public void setError(int status,String error) {
        this.status = status;
        this.error = error;
        this.message = error;
    }
    
    public void setMessage(int status,String message) {
        this.status = status;
        this.message = message;
    }
    
    public void putData(String sKey, Object oValue) {
        data.put(sKey, oValue);
    }

    public Object takeData(String sKey, Object sDefault) {
        Object objRtn = data.get(sKey);
        if (objRtn == null) {
            objRtn = sDefault;
        }
        return objRtn;
    }

    public Object takeData(String aKey) {
        return takeData(aKey, null);
    }
}
